class Solution2 {
    public int longestOnes(int[] nums, int k) {
        int left = 0;
        int right = 0;
        int zero = 0;
        int ret = 0;
        while(right < nums.length) {
            if(nums[right] == 0)    zero++;
            while(zero > k) {
                if(nums[left++] == 0) {
                    zero--;
                }
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        return ret;
    }

}